import type {
  BaseStatus,
  OptionsStatus,
  OptionsStatusArr,
  OptionsStatusByIndexPayload,
  PicLink,
  PicTitleDescStatusArr,
  TypeStatus,
  ValueStatusArr,
} from './editProps';

/*
 * @Author: jhw
 * @Date: 2025-08-06 14:16:33
 * @LastEditors: jhw
 * @LastEditTime: 2025-08-13 15:03:15
 * @Description:
 */
export const IsOptionsStatus = (status: BaseStatus): status is OptionsStatus => {
  return 'options' in status;
};

export const IsTypeStatus = (status: BaseStatus): status is TypeStatus => {
  return 'type' in status;
};

/**
 * 判断是否是字符串数组
 * @param status 状态
 * @returns 是否是字符串数组
 */
export const isStringArray = (status: OptionsStatusArr): status is string[] => {
  return Array.isArray(status) && typeof status[0] === 'string';
};

/**
 * 判断是否是值数组
 * @param status 状态
 * @returns 是否是值数组
 */
export const isValueArray = (status: OptionsStatusArr): status is ValueStatusArr => {
  return Array.isArray(status) && typeof status[0] === 'object' && 'value' in status[0];
};

/**
 * 判断是否是图片标题描述数组
 * @param status 状态
 * @returns 是否是图片标题描述数组
 */
export const isPicTitleDescArray = (status: OptionsStatusArr): status is PicTitleDescStatusArr => {
  return Array.isArray(status) && typeof status[0] === 'object' && 'picTitle' in status[0];
};

/**
 * 判断是否是图片链接
 * @param payload
 * @returns 是否是图片链接
 */
export const isPicLink = (payload: object): payload is PicLink => {
  return typeof payload === 'object' && 'link' in payload && 'index' in payload;
};

// 判断传入的值 是否是 note-desc 组件的类型
export const isNoteDesc = (payload: string) => {
  return payload === 'note-desc';
};

export const isOptionsStatusByIndexPayload = (
  payload: object,
): payload is OptionsStatusByIndexPayload => {
  return typeof payload === 'object' && 'val' in payload && 'index' in payload;
};
